namespace QMVnSoft.Invoices
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.Controls.ChildGridControls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCTSX1F4Editor : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private BtnControl btnShowAll;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column18;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewCheckBoxColumn Column6;
        private DataGridViewCheckBoxColumn Column7;
        private DataGridViewTextBoxColumn Column8;
        private IContainer components;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn6;
        private SplitContainer grdContainer;
        private GridControl grdDetail;
        private GridControl grdMaster;
        private SplitContainer grdSubContainer;
        private GridControl grdSubDetail;
        private bool ib_CheckAccepted;
        private bool ib_FirstTime = true;
        private object is_DetailKey;
        private object is_MasterKey;
        private object is_ParentDate;
        private object is_ParentKey;
        private NumericColumn numericColumn1;
        private NumericColumn numericColumn10;
        private DataGridViewTextBoxColumn numericColumn11;
        private DataGridViewTextBoxColumn numericColumn12;
        private NumericColumn numericColumn13;
        private NumericColumn numericColumn14;
        private NumericColumn numericColumn15;
        private NumericColumn numericColumn16;
        private NumericColumn numericColumn17;
        private NumericColumn numericColumn2;
        private NumericColumn numericColumn3;
        private NumericColumn numericColumn4;
        private NumericColumn numericColumn5;
        private NumericColumn numericColumn6;
        private NumericColumn numericColumn7;
        private NumericColumn numericColumn8;
        private NumericColumn numericColumn9;
        private HeaderCheck oDetailHeader;
        private AppInvoiceLib oAppInvoiceLib;
        private DataTable oLocalDetailTable;
        private DataTable oLocalMasterTable;
        private DataTable oLocalSelectedTable;
        private DataTable oLocalSubDetailTable;
        private CTNXDataAccess oMethod = new CTNXDataAccess();

        public FormCTSX1F4Editor(object ps_ParentKey, object pd_ParentDate, DataTable po_SelectedTable)
        {
            this.InitializeComponent();
            this.InvoiceCode = "PLSX";
            this.ParentKey = ps_ParentKey;
            this.ParentDate = pd_ParentDate;
            this.LocalSelectedTable = po_SelectedTable;
            this.grdMaster.AutoGenerateColumns = false;
            this.grdDetail.AutoGenerateColumns = false;
            this.grdSubDetail.AutoGenerateColumns = false;
            this.oDetailHeader = new HeaderCheck();
            this.Column7.HeaderCell = this.oDetailHeader;
            this.Column7.HeaderText = "";
            this.oDetailHeader.OnCheckBoxClicked += new CheckBoxClickedHandler(this.oDetailHeader_OnCheckBoxClicked);
            this.OnResetControls();
            this.OnFillData();
            base.ResizeForm();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.OnSelected();
            this.CheckAccepted = true;
            base.Close();
        }

        private void btnShowAll_Click(object sender, EventArgs e)
        {
            this.ib_FirstTime = false;
            this.OnFillData();
        }

        private void DetailGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if ((this.DetailGrid.CurrentRow != null) || (this.DetailGrid.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) this.DetailGrid.CurrentRow.DataBoundItem).Row;
                this.DetailKey = row["Stt0"].ToString();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            DataGridViewCellStyle style3 = new DataGridViewCellStyle();
            DataGridViewCellStyle style4 = new DataGridViewCellStyle();
            DataGridViewCellStyle style5 = new DataGridViewCellStyle();
            DataGridViewCellStyle style6 = new DataGridViewCellStyle();
            DataGridViewCellStyle style7 = new DataGridViewCellStyle();
            DataGridViewCellStyle style8 = new DataGridViewCellStyle();
            DataGridViewCellStyle style9 = new DataGridViewCellStyle();
            DataGridViewCellStyle style10 = new DataGridViewCellStyle();
            DataGridViewCellStyle style11 = new DataGridViewCellStyle();
            DataGridViewCellStyle style12 = new DataGridViewCellStyle();
            DataGridViewCellStyle style13 = new DataGridViewCellStyle();
            DataGridViewCellStyle style14 = new DataGridViewCellStyle();
            DataGridViewCellStyle style15 = new DataGridViewCellStyle();
            this.grdContainer = new SplitContainer();
            this.grdMaster = new GridControl();
            this.Column1 = new DataGridViewTextBoxColumn();
            this.Column2 = new DataGridViewTextBoxColumn();
            this.Column3 = new DataGridViewTextBoxColumn();
            this.Column18 = new DataGridViewTextBoxColumn();
            this.Column4 = new DataGridViewTextBoxColumn();
            this.Column5 = new DataGridViewTextBoxColumn();
            this.Column6 = new DataGridViewCheckBoxColumn();
            this.grdSubContainer = new SplitContainer();
            this.grdDetail = new GridControl();
            this.grdSubDetail = new GridControl();
            this.dataGridViewTextBoxColumn4 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn5 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn6 = new DataGridViewTextBoxColumn();
            this.Column8 = new DataGridViewTextBoxColumn();
            this.numericColumn11 = new DataGridViewTextBoxColumn();
            this.numericColumn12 = new DataGridViewTextBoxColumn();
            this.numericColumn13 = new NumericColumn();
            this.numericColumn14 = new NumericColumn();
            this.numericColumn15 = new NumericColumn();
            this.numericColumn16 = new NumericColumn();
            this.numericColumn17 = new NumericColumn();
            this.Column7 = new DataGridViewCheckBoxColumn();
            this.btnShowAll = new BtnControl();
            this.btnOk = new BtnControl();
            this.btnCancel = new BtnControl();
            this.dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
            this.numericColumn1 = new NumericColumn();
            this.numericColumn2 = new NumericColumn();
            this.numericColumn3 = new NumericColumn();
            this.numericColumn4 = new NumericColumn();
            this.numericColumn5 = new NumericColumn();
            this.numericColumn6 = new NumericColumn();
            this.numericColumn7 = new NumericColumn();
            this.numericColumn8 = new NumericColumn();
            this.numericColumn9 = new NumericColumn();
            this.numericColumn10 = new NumericColumn();
            this.grdContainer.Panel1.SuspendLayout();
            this.grdContainer.Panel2.SuspendLayout();
            this.grdContainer.SuspendLayout();
            ((ISupportInitialize) this.grdMaster).BeginInit();
            this.grdSubContainer.Panel1.SuspendLayout();
            this.grdSubContainer.Panel2.SuspendLayout();
            this.grdSubContainer.SuspendLayout();
            ((ISupportInitialize) this.grdDetail).BeginInit();
            ((ISupportInitialize) this.grdSubDetail).BeginInit();
            base.SuspendLayout();
            this.grdContainer.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.grdContainer.Location = new Point(0, 0x2d);
            this.grdContainer.Name = "grdContainer";
            this.grdContainer.Orientation = Orientation.Horizontal;
            this.grdContainer.Panel1.Controls.Add(this.grdMaster);
            this.grdContainer.Panel2.Controls.Add(this.grdSubContainer);
            this.grdContainer.Size = new Size(0x31a, 0x1e7);
            this.grdContainer.SplitterDistance = 160;
            this.grdContainer.SplitterWidth = 1;
            this.grdContainer.TabIndex = 0;
            this.grdMaster.AllowUserToAddRows = false;
            this.grdMaster.AllowUserToDeleteRows = false;
            this.grdMaster.CheckAutoSize = true;
            this.grdMaster.CheckColor = false;
            this.grdMaster.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdMaster.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column18, this.Column4, this.Column5, this.Column6 });
            this.grdMaster.Dock = DockStyle.Fill;
            this.grdMaster.Font = new Font("Arial", 8.25f);
            this.grdMaster.Location = new Point(0, 0);
            this.grdMaster.Name = "grdMaster";
            this.grdMaster.Size = new Size(0x31a, 160);
            this.grdMaster.TabIndex = 1;
            this.grdMaster.CellEnter += new DataGridViewCellEventHandler(this.MasterGrid_CellEnter);
            this.Column1.DataPropertyName = "Ngay_Ct";
            this.Column1.HeaderText = "Ngày";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Resizable = DataGridViewTriState.False;
            this.Column1.Width = 0x3e;
            this.Column2.DataPropertyName = "So_Ct";
            this.Column2.HeaderText = "Số";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 0x44;
            this.Column3.DataPropertyName = "Dien_Giai";
            this.Column3.HeaderText = "Diễn giải (VN)";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Width = 0xab;
            this.Column18.DataPropertyName = "Desc_EN";
            this.Column18.HeaderText = "Diễn giải (EN)";
            this.Column18.Name = "Column18";
            this.Column18.ReadOnly = true;
            this.Column18.Width = 170;
            this.Column4.DataPropertyName = "Ten_YC";
            this.Column4.HeaderText = "Người yêu cầu";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 130;
            this.Column5.DataPropertyName = "Ten_NN";
            this.Column5.HeaderText = "Người nhận";
            this.Column5.Name = "Column5";
            this.Column5.ReadOnly = true;
            this.Column5.Resizable = DataGridViewTriState.True;
            this.Column5.Width = 130;
            this.Column6.DataPropertyName = "Marked";
            this.Column6.HeaderText = "";
            this.Column6.Name = "Column6";
            this.Column6.ReadOnly = true;
            this.Column6.Resizable = DataGridViewTriState.False;
            this.Column6.Width = 20;
            this.grdSubContainer.Dock = DockStyle.Fill;
            this.grdSubContainer.Location = new Point(0, 0);
            this.grdSubContainer.Name = "grdSubContainer";
            this.grdSubContainer.Orientation = Orientation.Horizontal;
            this.grdSubContainer.Panel1.Controls.Add(this.grdDetail);
            this.grdSubContainer.Panel2.Controls.Add(this.grdSubDetail);
            this.grdSubContainer.Size = new Size(0x31a, 0x146);
            this.grdSubContainer.SplitterDistance = 0xa1;
            this.grdSubContainer.SplitterWidth = 1;
            this.grdSubContainer.TabIndex = 1;
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new DataGridViewColumn[] { this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn2, this.dataGridViewTextBoxColumn3, this.numericColumn1, this.numericColumn2, this.numericColumn3, this.numericColumn4, this.numericColumn5, this.numericColumn6, this.numericColumn7, this.numericColumn8, this.numericColumn9, this.numericColumn10 });
            this.grdDetail.Dock = DockStyle.Fill;
            this.grdDetail.Font = new Font("Arial", 8.25f);
            this.grdDetail.Location = new Point(0, 0);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new Size(0x31a, 0xa1);
            this.grdDetail.TabIndex = 5;
            this.grdDetail.CellEnter += new DataGridViewCellEventHandler(this.DetailGrid_CellEndEdit);
            this.grdSubDetail.AllowUserToAddRows = false;
            this.grdSubDetail.AllowUserToDeleteRows = false;
            this.grdSubDetail.CheckAutoSize = true;
            this.grdSubDetail.CheckColor = false;
            this.grdSubDetail.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdSubDetail.Columns.AddRange(new DataGridViewColumn[] { this.dataGridViewTextBoxColumn4, this.dataGridViewTextBoxColumn5, this.dataGridViewTextBoxColumn6, this.Column8, this.numericColumn11, this.numericColumn12, this.numericColumn13, this.numericColumn14, this.numericColumn15, this.numericColumn16, this.numericColumn17, this.Column7 });
            this.grdSubDetail.Dock = DockStyle.Fill;
            this.grdSubDetail.Font = new Font("Arial", 8.25f);
            this.grdSubDetail.Location = new Point(0, 0);
            this.grdSubDetail.Name = "grdSubDetail";
            this.grdSubDetail.Size = new Size(0x31a, 0xa4);
            this.grdSubDetail.TabIndex = 6;
            this.grdSubDetail.CellEndEdit += new DataGridViewCellEventHandler(this.SubDetailGrid_CellEndEdit);
            this.dataGridViewTextBoxColumn4.DataPropertyName = "Ma_Vt";
            this.dataGridViewTextBoxColumn4.HeaderText = "Vật tư";
            this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
            this.dataGridViewTextBoxColumn4.ReadOnly = true;
            this.dataGridViewTextBoxColumn4.Width = 70;
            this.dataGridViewTextBoxColumn5.DataPropertyName = "Ten_Vt";
            this.dataGridViewTextBoxColumn5.HeaderText = "Tên vật tư";
            this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
            this.dataGridViewTextBoxColumn5.ReadOnly = true;
            this.dataGridViewTextBoxColumn5.Width = 180;
            this.dataGridViewTextBoxColumn6.DataPropertyName = "Dvt";
            this.dataGridViewTextBoxColumn6.HeaderText = "Đvt";
            this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";
            this.dataGridViewTextBoxColumn6.ReadOnly = true;
            this.dataGridViewTextBoxColumn6.Width = 0x1c;
            this.Column8.DataPropertyName = "Ma_Kho";
            this.Column8.HeaderText = "Kho hàng";
            this.Column8.Name = "Column8";
            this.Column8.ReadOnly = true;
            this.Column8.Width = 70;
            this.numericColumn11.DataPropertyName = "Lo_Hang";
            this.numericColumn11.HeaderText = "L\x00f4 hàng";
            this.numericColumn11.Name = "numericColumn11";
            this.numericColumn11.ReadOnly = true;
            this.numericColumn11.Resizable = DataGridViewTriState.True;
            this.numericColumn11.Width = 70;
            this.numericColumn12.DataPropertyName = "Han_Dung";
            this.numericColumn12.HeaderText = "Hạn d\x00f9ng";
            this.numericColumn12.Name = "numericColumn12";
            this.numericColumn12.ReadOnly = true;
            this.numericColumn12.Resizable = DataGridViewTriState.True;
            this.numericColumn12.Width = 0x3e;
            this.numericColumn13.DataPropertyName = "H_Luong";
            style.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn13.DefaultCellStyle = style;
            this.numericColumn13.HeaderText = "H\x00e0m lượng";
            this.numericColumn13.Name = "numericColumn13";
            this.numericColumn13.ReadOnly = true;
            this.numericColumn13.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn13.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn13.Width = 40;
            this.numericColumn14.DataPropertyName = "Do_Am_PT";
            style2.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn14.DefaultCellStyle = style2;
            this.numericColumn14.HeaderText = "Độ ẩm";
            this.numericColumn14.Name = "numericColumn14";
            this.numericColumn14.ReadOnly = true;
            this.numericColumn14.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn14.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn14.Width = 40;
            this.numericColumn15.DataPropertyName = "Do_Con_PT";
            style3.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn15.DefaultCellStyle = style3;
            this.numericColumn15.HeaderText = "Độ cồn";
            this.numericColumn15.Name = "numericColumn15";
            this.numericColumn15.ReadOnly = true;
            this.numericColumn15.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn15.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn15.Width = 40;
            this.numericColumn16.DataPropertyName = "So_Luong2";
            style4.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn16.DefaultCellStyle = style4;
            this.numericColumn16.HeaderText = "Tồn kho";
            this.numericColumn16.Name = "numericColumn16";
            this.numericColumn16.ReadOnly = true;
            this.numericColumn16.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn16.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn16.Width = 0x41;
            this.numericColumn17.DataPropertyName = "So_Luong";
            style5.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn17.DefaultCellStyle = style5;
            this.numericColumn17.HeaderText = "Xuất";
            this.numericColumn17.Name = "numericColumn17";
            this.numericColumn17.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn17.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn17.Width = 0x42;
            this.Column7.DataPropertyName = "Marked";
            this.Column7.HeaderText = "";
            this.Column7.Name = "Column7";
            this.Column7.Resizable = DataGridViewTriState.False;
            this.Column7.Width = 20;
            this.btnShowAll.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.btnShowAll.Font = new Font("Arial", 8.25f);
            this.btnShowAll.Location = new Point(470, 12);
            this.btnShowAll.Name = "btnShowAll";
            this.btnShowAll.Size = new Size(100, 0x17);
            this.btnShowAll.TabIndex = 0;
            this.btnShowAll.Text = "Hiện tất";
            this.btnShowAll.UseVisualStyleBackColor = true;
            this.btnShowAll.Click += new EventHandler(this.btnShowAll_Click);
            this.btnOk.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.btnOk.Font = new Font("Arial", 8.25f);
            this.btnOk.Location = new Point(0x240, 12);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(100, 0x17);
            this.btnOk.TabIndex = 1;
            this.btnOk.Text = "Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.btnCancel.Font = new Font("Arial", 8.25f);
            this.btnCancel.Location = new Point(0x2aa, 12);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(100, 0x17);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "Huỷ bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.dataGridViewTextBoxColumn1.DataPropertyName = "Ma_Vt";
            this.dataGridViewTextBoxColumn1.HeaderText = "Vật tư";
            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
            this.dataGridViewTextBoxColumn1.ReadOnly = true;
            this.dataGridViewTextBoxColumn1.Width = 60;
            this.dataGridViewTextBoxColumn2.DataPropertyName = "Ten_Vt";
            this.dataGridViewTextBoxColumn2.HeaderText = "Tên vật tư";
            this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
            this.dataGridViewTextBoxColumn2.ReadOnly = true;
            this.dataGridViewTextBoxColumn2.Width = 150;
            this.dataGridViewTextBoxColumn3.DataPropertyName = "Dvt";
            this.dataGridViewTextBoxColumn3.HeaderText = "Đvt";
            this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
            this.dataGridViewTextBoxColumn3.ReadOnly = true;
            this.dataGridViewTextBoxColumn3.Width = 0x1d;
            this.numericColumn1.DataPropertyName = "So_Luong0";
            style6.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn1.DefaultCellStyle = style6;
            this.numericColumn1.HeaderText = "Yêu cầu";
            this.numericColumn1.Name = "numericColumn1";
            this.numericColumn1.ReadOnly = true;
            this.numericColumn1.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn1.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn1.Width = 0x40;
            this.numericColumn2.DataPropertyName = "So_Luong1";
            style7.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn2.DefaultCellStyle = style7;
            this.numericColumn2.HeaderText = "Thực hiện";
            this.numericColumn2.Name = "numericColumn2";
            this.numericColumn2.ReadOnly = true;
            this.numericColumn2.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn2.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn2.Width = 0x40;
            this.numericColumn3.DataPropertyName = "Ton_Kho1";
            style8.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn3.DefaultCellStyle = style8;
            this.numericColumn3.HeaderText = "Tồn kho";
            this.numericColumn3.Name = "numericColumn3";
            this.numericColumn3.ReadOnly = true;
            this.numericColumn3.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn3.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn3.Width = 0x40;
            this.numericColumn4.DataPropertyName = "Ton_Kho2";
            style9.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn4.DefaultCellStyle = style9;
            this.numericColumn4.HeaderText = "Đơn hàng";
            this.numericColumn4.Name = "numericColumn4";
            this.numericColumn4.ReadOnly = true;
            this.numericColumn4.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn4.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn4.Visible = false;
            this.numericColumn4.Width = 0x40;
            this.numericColumn5.DataPropertyName = "Ton_Kho3";
            style10.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn5.DefaultCellStyle = style10;
            this.numericColumn5.HeaderText = "Thành phẩm";
            this.numericColumn5.Name = "numericColumn5";
            this.numericColumn5.ReadOnly = true;
            this.numericColumn5.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn5.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn5.Width = 0x40;
            this.numericColumn6.DataPropertyName = "Ton_Kho4";
            style11.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn6.DefaultCellStyle = style11;
            this.numericColumn6.HeaderText = "Yêu cầu nhập";
            this.numericColumn6.Name = "numericColumn6";
            this.numericColumn6.ReadOnly = true;
            this.numericColumn6.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn6.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn6.Visible = false;
            this.numericColumn6.Width = 0x40;
            this.numericColumn7.DataPropertyName = "Ton_Kho5";
            style12.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn7.DefaultCellStyle = style12;
            this.numericColumn7.HeaderText = "Yêu cầu xuất";
            this.numericColumn7.Name = "numericColumn7";
            this.numericColumn7.ReadOnly = true;
            this.numericColumn7.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn7.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn7.Width = 0x40;
            this.numericColumn8.DataPropertyName = "Ton_Kho0";
            style13.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn8.DefaultCellStyle = style13;
            this.numericColumn8.HeaderText = "Tổng";
            this.numericColumn8.Name = "numericColumn8";
            this.numericColumn8.ReadOnly = true;
            this.numericColumn8.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn8.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn8.Width = 0x40;
            this.numericColumn9.DataPropertyName = "So_Luong2";
            style14.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn9.DefaultCellStyle = style14;
            this.numericColumn9.HeaderText = "Còn lại";
            this.numericColumn9.Name = "numericColumn9";
            this.numericColumn9.ReadOnly = true;
            this.numericColumn9.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn9.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn9.Width = 0x40;
            this.numericColumn10.DataPropertyName = "So_Luong";
            style15.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.numericColumn10.DefaultCellStyle = style15;
            this.numericColumn10.HeaderText = "Lập";
            this.numericColumn10.Name = "numericColumn10";
            this.numericColumn10.ReadOnly = true;
            this.numericColumn10.SortMode = DataGridViewColumnSortMode.Automatic;
            this.numericColumn10.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            this.numericColumn10.Width = 0x40;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x31a, 0x214);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOk);
            base.Controls.Add(this.btnShowAll);
            base.Controls.Add(this.grdContainer);
            this.MinimumSize = new Size(0x322, 0x236);
            base.Name = "FormCTSX1F4Editor";
            this.grdContainer.Panel1.ResumeLayout(false);
            this.grdContainer.Panel2.ResumeLayout(false);
            this.grdContainer.ResumeLayout(false);
            ((ISupportInitialize) this.grdMaster).EndInit();
            this.grdSubContainer.Panel1.ResumeLayout(false);
            this.grdSubContainer.Panel2.ResumeLayout(false);
            this.grdSubContainer.ResumeLayout(false);
            ((ISupportInitialize) this.grdDetail).EndInit();
            ((ISupportInitialize) this.grdSubDetail).EndInit();
            base.ResumeLayout(false);
        }

        private void MasterGrid_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((this.MasterGrid.CurrentRow != null) || (this.MasterGrid.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) this.MasterGrid.CurrentRow.DataBoundItem).Row;
                this.MasterKey = row["Stt"].ToString();
            }
        }

        private void oDetailHeader_OnCheckBoxClicked(bool state)
        {
            this.SelectAllDetail(state);
        }

        private void OnFillData()
        {
            this.LocalMasterTable = this.oMethod.GetMasterCommandItem(this.ib_FirstTime, AppInstance.Subsidiary, this.ParentKey, this.ParentDate);
        }

        private void OnResetControls()
        {
            if (!this.AppInvoiceParameters.BilingualUsed)
            {
                this.MasterGrid.Columns[3].Visible = false;
            }
            if (!AppInstance.LotNumberCtrl)
            {
                this.SubDetailGrid.Columns[4].Visible = false;
            }
            if (!AppInstance.DeadLineCtrl)
            {
                this.SubDetailGrid.Columns[5].Visible = false;
            }
            if (!AppInstance.QualityCtrl)
            {
                this.SubDetailGrid.Columns[6].Visible = false;
            }
            if (!AppInstance.DampCtrl)
            {
                this.SubDetailGrid.Columns[7].Visible = false;
            }
            if (!AppInstance.AlcoholCtrl)
            {
                this.SubDetailGrid.Columns[8].Visible = false;
            }
        }

        private void OnSelected()
        {
            if ((this.LocalSubDetailTable != null) && (this.LocalSubDetailTable.Rows.Count != 0))
            {
                foreach (DataRow row2 in this.LocalSubDetailTable.Rows)
                {
                    if (row2.RowState != DataRowState.Deleted)
                    {
                        if (row2["So_Luong"].Equals(DBNull.Value))
                        {
                            row2["So_Luong"] = 0;
                        }
                        object[] keys = new object[] { row2["Stt0"], row2["Ma_Kho"], row2["Ma_Vt"], row2["Lo_Hang"] };
                        DataRow row = this.LocalSelectedTable.Rows.Find(keys);
                        if (row == null)
                        {
                            row = this.LocalSelectedTable.NewRow();
                        }
                        row["Stt0_D"] = row2["Stt0"];
                        row["Ma_Bp"] = row2["Ma_Bp"];
                        row["Ma_Hd"] = row2["Ma_Hd"];
                        row["Ma_Kho"] = row2["Ma_Kho"];
                        row["Ma_Vt"] = row2["Ma_Vt"];
                        row["Ten_Vt"] = row2["Ten_Vt"];
                        row["Dvt"] = row2["Dvt"];
                        row["Lo_Hang"] = row2["Lo_Hang"];
                        row["Han_Dung"] = row2["Han_Dung"];
                        row["H_Luong"] = row2["H_Luong"];
                        row["Do_Am_PT"] = row2["Do_Am_PT"];
                        row["Do_Con_PT"] = row2["Do_Con_PT"];
                        row["So_Luong"] = row2["So_Luong"];
                        if (row.RowState == DataRowState.Detached)
                        {
                            this.LocalSelectedTable.Rows.Add(row);
                        }
                    }
                }
            }
        }

        private void OnShowDetail()
        {
            this.OnSelected();
            this.LocalDetailTable = this.oMethod.GetDetailCommandItem(this.MasterKey, this.ParentKey, this.ParentDate);
            foreach (DataRow row2 in this.LocalDetailTable.Rows)
            {
                if (row2.RowState != DataRowState.Deleted)
                {
                    if (row2["Ma_Vt_Nh"].ToString() == "N")
                    {
                        foreach (DataRow row3 in this.LocalSelectedTable.Rows)
                        {
                            if (row2["So_Luong"].Equals(DBNull.Value))
                            {
                                row2["So_Luong"] = 0;
                            }
                            if (row2["Stt0"].Equals(row3["Stt0_D"]))
                            {
                                row2["So_Luong"] = ((decimal) row2["So_Luong"]) + ((decimal) row3["So_Luong"]);
                            }
                            if (!row2["Stt0"].Equals(row3["Stt0_D"]))
                            {
                                DataRow row = AppDataAccess.SelectDataRow(false, "DMVT", "Ma_Vt", row3["Ma_Vt"].ToString(), null);
                                if ((row != null) && row2["Ma_Vt"].Equals(row["Ma_Nh_Dm"]))
                                {
                                    row2["Ton_Kho1"] = ((decimal) row2["Ton_Kho1"]) - ((decimal) row3["So_Luong"]);
                                    row2["Ton_Kho0"] = ((decimal) row2["Ton_Kho0"]) - ((decimal) row3["So_Luong"]);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (DataRow row4 in this.LocalSelectedTable.Rows)
                        {
                            if (row2["So_Luong"].Equals(DBNull.Value))
                            {
                                row2["So_Luong"] = 0;
                            }
                            if (row2["Stt0"].Equals(row4["Stt0_D"]))
                            {
                                row2["So_Luong"] = ((decimal) row2["So_Luong"]) + ((decimal) row4["So_Luong"]);
                            }
                            if (!row2["Stt0"].Equals(row4["Stt0_D"]) && row2["Ma_Vt"].Equals(row4["Ma_Vt"]))
                            {
                                row2["Ton_Kho1"] = ((decimal) row2["Ton_Kho1"]) - ((decimal) row2["So_Luong"]);
                                row2["Ton_Kho0"] = ((decimal) row2["Ton_Kho0"]) - ((decimal) row2["So_Luong"]);
                            }
                        }
                    }
                }
            }
        }

        private void OnShowSubDetail()
        {
            this.OnSelected();
            this.LocalSubDetailTable = this.oMethod.GetSubDetailCommandItem(this.ParentDate, this.DetailKey);
            foreach (DataRow row2 in this.LocalSubDetailTable.Rows)
            {
                if (row2.RowState != DataRowState.Deleted)
                {
                    object[] keys = new object[] { row2["Stt0"], row2["Ma_Kho"], row2["Ma_Vt"], row2["Lo_Hang"] };
                    DataRow row = this.LocalSelectedTable.Rows.Find(keys);
                    if (row != null)
                    {
                        row2["So_Luong"] = row["So_Luong"];
                        row2["Marked"] = row2["So_Luong2"].Equals(row2["So_Luong"]);
                    }
                }
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.OnSelected();
                this.CheckAccepted = true;
                base.Close();
            }
            else if (keyData == Keys.Escape)
            {
                base.Close();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void SelectAllDetail(bool pb_State)
        {
            if ((this.LocalSubDetailTable != null) && (this.LocalSubDetailTable.Rows.Count != 0))
            {
                foreach (DataRow row in this.LocalSubDetailTable.Rows)
                {
                    if (row.RowState != DataRowState.Deleted)
                    {
                        this.SelectOneDetail(row, pb_State);
                    }
                }
                this.Sum();
            }
        }

        private void SelectOneDetail(DataRow po_Row, bool pb_State)
        {
            if (po_Row != null)
            {
                if (pb_State)
                {
                    po_Row["So_Luong"] = po_Row["So_Luong2"];
                    po_Row["Marked"] = true;
                }
                else
                {
                    po_Row["So_Luong"] = 0;
                    po_Row["Marked"] = false;
                }
            }
        }

        private void SubDetailGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataRow row = ((DataRowView) this.DetailGrid.CurrentRow.DataBoundItem).Row;
        }

        private void Sum()
        {
            decimal num = 0M;
            foreach (DataRow row in this.LocalSubDetailTable.Rows)
            {
                if ((row.RowState != DataRowState.Deleted) && !row["So_Luong"].Equals(DBNull.Value))
                {
                    num += (decimal) row["So_Luong"];
                }
            }
            ((DataRowView) this.DetailGrid.CurrentRow.DataBoundItem).Row["So_Luong"] = num;
        }

        public bool CheckAccepted
        {
            get
            {
                return this.ib_CheckAccepted;
            }
            set
            {
                this.ib_CheckAccepted = value;
            }
        }

        private GridControl DetailGrid
        {
            get
            {
                return this.grdDetail;
            }
        }

        private object DetailKey
        {
            get
            {
                return this.is_DetailKey;
            }
            set
            {
                if (this.is_DetailKey != value)
                {
                    this.is_DetailKey = value;
                    this.OnShowSubDetail();
                }
            }
        }

        private AppInvoiceLib AppInvoiceParameters
        {
            get
            {
                if (this.oAppInvoiceLib == null)
                {
                    this.AppInvoiceParameters = new AppInvoiceLib();
                }
                return this.oAppInvoiceLib;
            }
            set
            {
                this.oAppInvoiceLib = value;
            }
        }

        private string InvoiceCode
        {
            get
            {
                if (this.AppInvoiceParameters == null)
                {
                    return "";
                }
                return this.AppInvoiceParameters.InvoiceCode;
            }
            set
            {
                if (this.AppInvoiceParameters != null)
                {
                    this.AppInvoiceParameters.InvoiceCode = value;
                    if (!string.IsNullOrEmpty(this.AppInvoiceParameters.InvoiceCode))
                    {
                        this.Text = this.AppInvoiceParameters.InvoiceName;
                    }
                }
            }
        }

        private DataTable LocalDetailTable
        {
            get
            {
                return this.oLocalDetailTable;
            }
            set
            {
                this.oLocalDetailTable = value;
                this.oLocalDetailTable.Columns.Add(new DataColumn("So_Luong", typeof(decimal)));
                this.DetailGrid.DataSource = new BindingSource(this.oLocalDetailTable, this.oLocalDetailTable.TableName);
            }
        }

        private DataTable LocalMasterTable
        {
            get
            {
                return this.oLocalMasterTable;
            }
            set
            {
                this.oLocalMasterTable = value;
                this.MasterGrid.DataSource = new BindingSource(this.oLocalMasterTable, this.oLocalMasterTable.TableName);
            }
        }

        private DataTable LocalSelectedTable
        {
            get
            {
                return this.oLocalSelectedTable;
            }
            set
            {
                this.oLocalSelectedTable = value;
            }
        }

        private DataTable LocalSubDetailTable
        {
            get
            {
                return this.oLocalSubDetailTable;
            }
            set
            {
                this.oLocalSubDetailTable = value;
                this.oLocalSubDetailTable.Columns.Add(new DataColumn("So_Luong", typeof(decimal)));
                this.SubDetailGrid.DataSource = new BindingSource(this.oLocalSubDetailTable, this.oLocalSubDetailTable.TableName);
            }
        }

        private GridControl MasterGrid
        {
            get
            {
                return this.grdMaster;
            }
        }

        private object MasterKey
        {
            get
            {
                return this.is_MasterKey;
            }
            set
            {
                if (this.is_MasterKey != value)
                {
                    this.is_MasterKey = value;
                    this.OnShowDetail();
                }
            }
        }

        private object ParentDate
        {
            get
            {
                return this.is_ParentDate;
            }
            set
            {
                this.is_ParentDate = value;
            }
        }

        private object ParentKey
        {
            get
            {
                return this.is_ParentKey;
            }
            set
            {
                this.is_ParentKey = value;
            }
        }

        private GridControl SubDetailGrid
        {
            get
            {
                return this.grdSubDetail;
            }
        }
    }
}

